package com.study.springboot2.controller;


import com.study.springboot2.entity.User;
import com.study.springboot2.service.UserService;
import com.study.springboot2.utils.StateParameter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping(value="/first")
@Slf4j
public class FirstController extends BaseController {

    @Autowired
    UserService userService;

    @RequestMapping(value="/view")
    public String view(HttpServletRequest request){

        List<User> list = userService.findAll();
        request.setAttribute("list", list);
        logger.info("返回列表页面");

        return "/firstPage";
    }

    @RequestMapping(value="/json", method = RequestMethod.GET)
    @ResponseBody
    public ModelMap back(HttpServletRequest request){
        log.info("进入json测试页面");
        return getModelMap(StateParameter.SUCCESS, new User(), "请求成功");
    }

}
